#{extends 'AdminM/main.html'/}

#{set 'moreScripts'}
<script src="@{'/public/ckeditor/ckeditor.js'}" type="text/javascript" charset="utf-8"></script>
<script src="@{'/public/ckeditor/adapters/jquery.js'}" type="text/javascript" charset="utf-8"></script>



<link href="@{'/public/uploadify/uploadify.css'}" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="@{'/public/uploadify/swfobject.js'}"></script>
<script type="text/javascript" src="@{'/public/uploadify/jquery.uploadify.v2.1.4.min.js'}"></script>
#{/set}

<style>
*{ 覆盖上传进度条样式 }*
.uploadifyQueueItem{width: 100%};
</style>

<script>
$(function(){
	$( 'textarea' ).ckeditor(); //使用ckeditor
	
	/*
	var uploader = new qq.FileUploader({
                element: $("#commodity-image p")[0],
                action: '@{Attachments.create_valums}',
                debug: true
            });*/

	/* uploadify2 */
	$('#image_upload').uploadify({
	    uploader	: '@{'/public/uploadify/uploadify.swf'}',
	    script		: '@{Attachments.create_uploadify}',
	    cancelImg	: '@{'/public/uploadify/cancel.png'}',
	    fileDataName: 'file',
	    fileExt     : '*.jpg;*.gif;*.png',
    	auto		: true,
    	onComplete	: function(event, ID, fileObj, response, data){
    		//显示附件
    		var getAttachmentAction = #{jsAction @Attachments.show(':id') /}
    		$("#image").attr('src', getAttachmentAction({id: response}));
    		//将附件ID添加到form里面
    		$("#image_upload").val(response);
    	}
	});
});
</script>

<style>
#commodity-image{
	float: right;
	margin-top: 20px; margin-right: 20px;
}
#commodity-image #image{
	display: block; width: 225px; height: 225px;
}
#new-form{
	font-size: 1.4em;
}
#new-form p{
	margin: 10px 0;
	display: inline-block;
}
</style>

#{form @Commodities.create(), id:'new-form'}
	
	#{ifErrors}
        <p class="error">
            Please correct these errors.
        </p>
    #{/ifErrors}
    <fieldset>
    <div id="commodity-image">
    	<img id="image" src="@{'/public/images/image-placeholder.png'}"/>
    	<p><input id="image_upload" type="text" name="image_id" /></p>
    </div>
    <p>
        #{field 'commodity.name'}
        <label>商品名称:</label>
        <input type="text" name="${field.name}" 
            value="${commodity?.name}" class="${field.errorClass}" />
        #{/field}
    </p>
    <p>
        #{field 'commodity.SN'}
        <label>商品编号:</label>
        <input type="text" name="${field.name}" 
            value="${commodity?.SN}" class="${field.errorClass}" />
        #{/field}
    </p>
    <p>    
        #{field 'commodity.manufacturerSN'}
        <label>厂家编号:</label>
        <input type="text" name="${field.name}" 
            value="${commodity?.manufacturerSN}" class="${field.errorClass}" />
        #{/field}
    </p>
    
    <p>
        #{field 'commodity.unit'}
        <label>商品单位:</label>
        <input type="text" name="${field.name}" 
            value="${commodity?.unit}" class="${field.errorClass}" />
        #{/field}
    </p>
    <p>
        #{field 'commodity.size'}
        <label>商品尺寸:</label>
        <input type="text" name="${field.name}" 
            value="${commodity?.size}" class="${field.errorClass}" />
        #{/field}
    </p>
    <p>
        #{field 'commodity.material'}
        <label>商品材质:</label>
        <input type="text" name="${field.name}" 
            value="${commodity?.material}" class="${field.errorClass}" />
        #{/field}
    </p>
    <p>
        #{field 'commodity.placeOfOrigin'}
        <label>商品产地:</label>
        <input type="text" name="${field.name}" 
            value="${commodity?.placeOfOrigin}" class="${field.errorClass}" />
        #{/field}
    </p>
    <p>
        #{field 'commodity.packaging'}
        <label>包&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;装:</label>
        <input type="text" name="${field.name}" 
            value="${commodity?.packaging}" class="${field.errorClass}" />
        #{/field}
    </p>
    <p>    
        #{field 'commodity.numberPerBox'}
        <label>装箱数量:</label>
        <input type="text" name="${field.name}" 
            value="${commodity?.numberPerBox}" class="${field.errorClass}" />
        #{/field}
    </p>
    <p>
    	<label>重量/毛重/净重</label>
        #{field 'commodity.weight'}
        <input type="text" name="${field.name}" 
            value="${commodity?.weight}" class="${field.errorClass}" />
        #{/field}
        #{field 'commodity.grossWeight'}
        <input type="text" name="${field.name}" 
            value="${commodity?.grossWeight}" class="${field.errorClass}" />
        #{/field}
        #{field 'commodity.netWeight'}
        <input type="text" name="${field.name}" 
            value="${commodity?.netWeight}" class="${field.errorClass}" />
        #{/field}
    </p>
    </fieldset>
    <fieldset>
    <p>
        #{field 'commodity.description'}
        <label>商品描述:</label>
        <textarea name="${field.name}" class="${field.errorClass}">${commodity?.description}</textarea>
        #{/field}
    </p>
    </fieldset> 
    <p>
    	<input type="submit" value="创建商品" />
    </p>
#{/form}